package com.ruoyi.system.service.impl.basic;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.dto.VehicleDto;
import com.ruoyi.system.domain.vo.VehicleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.basic.BasicVehiclesMapper;
import com.ruoyi.system.domain.db.basic.BasicVehicles;
import com.ruoyi.system.service.IBasicVehiclesService;

/**
 * 汽车管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-07-25
 */
@Service
public class BasicVehiclesServiceImpl implements IBasicVehiclesService
{
    @Autowired
    private BasicVehiclesMapper basicVehiclesMapper;

    /**
     * 查询汽车管理
     * 
     * @param vehicleId 汽车管理主键
     * @return 汽车管理
     */
    @Override
    public VehicleDto selectBasicVehiclesByVehicleId(Long vehicleId)
    {
        return basicVehiclesMapper.selectBasicVehiclesByVehicleId(vehicleId);
    }

    /**
     * 查询汽车管理列表
     * 
     * @param basicVehicles 汽车管理
     * @return 汽车管理
     */
    @Override
    public List<VehicleDto> selectBasicVehiclesList(BasicVehicles basicVehicles)
    {
        return basicVehiclesMapper.selectBasicVehiclesList(basicVehicles);
    }

    /**
     * 新增汽车管理
     * 
     * @param basicVehicles 汽车管理
     * @return 结果
     */
    @Override
    public int insertBasicVehicles(BasicVehicles basicVehicles)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Date nowDate = DateUtils.getNowDate();
        basicVehicles.setCreateTime(nowDate);
        basicVehicles.setUpdateTime(nowDate);
        basicVehicles.setUpdateBy(loginUser.getUserId());
        basicVehicles.setCreateBy(loginUser.getUserId());
        return basicVehiclesMapper.insertBasicVehicles(basicVehicles);
    }

    /**
     * 修改汽车管理
     * 
     * @param basicVehicles 汽车管理
     * @return 结果
     */
    @Override
    public int updateBasicVehicles(BasicVehicles basicVehicles)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Date nowDate = DateUtils.getNowDate();
        basicVehicles.setUpdateTime(nowDate);
        basicVehicles.setUpdateBy(loginUser.getUserId());
        return basicVehiclesMapper.updateBasicVehicles(basicVehicles);
    }

    /**
     * 批量删除汽车管理
     * 
     * @param vehicleIds 需要删除的汽车管理主键
     * @return 结果
     */
    @Override
    public int deleteBasicVehiclesByVehicleIds(Long[] vehicleIds)
    {
        return basicVehiclesMapper.deleteBasicVehiclesByVehicleIds(vehicleIds);
    }

    /**
     * 删除汽车管理信息
     * 
     * @param vehicleId 汽车管理主键
     * @return 结果
     */
    @Override
    public int deleteBasicVehiclesByVehicleId(Long vehicleId)
    {
        return basicVehiclesMapper.deleteBasicVehiclesByVehicleId(vehicleId);
    }

    /**
     * Dto转Vo
     *
     * @param vehicleDto 汽车管理Dto
     * @return
     */
    @Override
    public VehicleVo DtoConvertToVo(VehicleDto vehicleDto) {
        VehicleVo vehicleVo = new VehicleVo();
        vehicleVo.setVehicleId(vehicleDto.getVehicleId());
        vehicleVo.setDriverName(vehicleDto.getDriver().getUserName());
        vehicleVo.setDriverPhoneNumber(vehicleDto.getDriver().getPhonenumber());
        vehicleVo.setVehicleNumber(vehicleDto.getVehicleNumber());
        vehicleVo.setManufacturer(vehicleDto.getManufacturer());
        vehicleVo.setModel(vehicleDto.getModel());
        vehicleVo.setCapacity(vehicleDto.getCapacity());
        vehicleVo.setState(vehicleDto.getState());
        vehicleVo.setRegistrationDate(vehicleDto.getRegistrationDate());
        vehicleVo.setLastMaintenanceDate(vehicleDto.getLastMaintenanceDate());
        vehicleVo.setDriverId(vehicleDto.getDriver().getUserId());
        return vehicleVo;
    }
}
